<!-- 包材品牌定义 ：蹇泽阳 -->
<template>
  <div class="app-container">
    <Find :OriginalFilter="{ static: true }" @Launchform="Launchform1" :formList="formList" @findClicked="findData" />

    <div class="flex mt10 main">
      <el-card shadow="never" :body-style="{ padding: '13px' }">
        <div slot="header">
          <span style="font-weight: 600">品牌明细</span>
        </div>
        <Table
          :isLoading="isLoading"
          @currentRow="currentRowListOeder"
          :tableHeader="tableHeader"
          :tableData="tableData"
          :TableHeight="100"
          :outTableHeight="40"
        >
        </Table>
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '13px' }">
        <div slot="header">
          <span style="font-weight: 600">包材分类明细</span>
        </div>
        <Table
          :isLoading="isLoading4"
          @currentRow="currentRowListOeder1"
          @selectValChange="selectedList"
          @checkboxChange="change10"
          :tableHeader="tableHeader2"
          :tableData="tableData2"
          selection
          :TableHeight="100"
          :outTableHeight="40"
        >
        </Table>
      </el-card>
      <el-card shadow="never" :body-style="{ padding: '13px' }">
        <div slot="header">
          <span style="font-weight: 600">材料明细</span>
        </div>
        <Table
          @inputChange="checkboxChange2"
          :isLoading="isLoading2"
          @currentRow="currentRowListOeder2"
          class="table1"
          :tableHeader="tableHeader7"
          :tableData="MaterialDetailnquiryMethodsTableDateList"
          selection
          :TableHeight="100"
          :outTableHeight="40"
        >
        </Table>
      </el-card>
    </div>

    <!-- 品牌新增 -->
    <el-dialog :close-on-click-modal="false" v-model="dialogVisible8" width="50%" class="dialog pb0">
      <Find :OriginalFilter="{ static: true }" @Launchform="Launchform2" :searchImg="false" :formList="formList1" @findClicked="findData1" />
    </el-dialog>

    <!-- 品牌新增 -->
    <el-dialog :close-on-click-modal="false" v-model="dialogVisible1" width="50%" class="dialog pb0">
      <Table
        @selectList="selectList"
        selection
        :isLoading="isLoading3"
        @currentRow="currentList"
        :tableHeader="tableHeader5"
        :tableData="packingMaterialsMethodsTableDateLsit"
        :TableHeight="'100'"
      ></Table>
      <el-button type="primary" size="default" @click="AdddeletepackingMethods">确认添加</el-button>
    </el-dialog>

    <!-- 选择材料 -->
    <el-dialog :close-on-click-modal="false" v-model="dialogVisible7" width="50%">
      <Find :OriginalFilter="{ static: true }" :searchImg="false" @Launchform="Launchform3" :formList="formList3" @findClicked="findData2" />
      <Table
        @inputChange="checkboxChange1"
        @currentRow="currentRowList"
        @currentRow1="currentRowList7"
        :isLoading="isLoading7"
        :tableHeader="tableHeader3"
        :tableData="NewOrderDetailsTableDate"
        :TableHeight="34"
      />
      <PageModule :PageData="{ buttonS: true, total: totalList1 }" @pageChange="pageChange11" @pageSizeChange="pageSizeChange11" />
      <h1 style="margin-top: 15px; color: black; font-size: 16px">物料资料建档</h1>
      <Find :OriginalFilter="{ static: true }" :searchImg="false" :formList="formList5" @Launchform="Launchform7" @findClicked="findData5" />
    </el-dialog>

    <el-dialog :close-on-click-modal="false" v-model="dialogVisible10" width="50%">
      <el-button type="primary" size="default" @click="AddPackingModeMethods">新增</el-button>
      <el-button type="primary" size="default" @click="DefinePackingModeMethods">保存</el-button>

      <Table :isLoading="isLoading8" :tableHeader="tableHeader10" :tableData="PackingMethodQueryTableDate" :TableHeight="34" />
    </el-dialog>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import JMessage from '@/utils/JMessage'
import service from '@/utils/request'
export default defineComponent({
  name: 'PackagingMaterialBrandDefinition'
})
</script>
<script lang="ts" setup>
import {
  DefinePackingMode,
  PackingMethodQuery,
  deleteWholeBrand,
  MaterialDetailsAdded,
  deleteMtlName,
  DeleteSelectMaterialNew,
  SelectMaterialNew,
  AddBrandDate,
  selectMaterials,
  PackingMethod,
  deleteMaterialDetail,
  Adddeletepacking,
  MaterialDetailnquiry,
  deletepackingMaterials,
  packingMaterialsQuery,
  deleteBrand,
  BrandMaterQuery,
  AddBrand,
  SelectackingMaterialClassification
} from '@/api/PurchasingDepartment/FactoryPurchasing/BrandPackaging'
import { packingMaterials } from '@/api/PurchasingDepartment/FactoryPurchasing/PackagingMaterialCategoryDefinition'
import {
  AddGeneratedMaterialCoding,
  GeneratedMaterialCoding,
  MaterialClassificationQuery,
  NewOrderDetails
} from '@/api/PurchasingDepartment/FactoryPurchasing/PackagingMaterialsOtherOrder'
import { GainClassification } from '@/api/WarehouseDepartment/FactoryStorage/ConsumablesIn'
import { ElMessage, ElMessageBox } from 'element-plus'
// 装箱方式新增
const DefinePackingModeMethods = async () => {
  const result = (await service.post('/mes/packBrand/addBoxingStyle', [PackingMethodQueryTableDate.value.pop()])) as any
  if (result.code === 200) {
    PackingMethodQueryMethods()
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

const isLoading8 = ref(false)

const AddPackingModeMethodsParms = ref({
  seqNo: '',
  packType: '',
  caseQty: '',
  change: 'Y',
  disableConfirm: true
})

const AddPackingModeMethods = (row: any) => {
  PackingMethodQueryTableDate.value.push(AddPackingModeMethodsParms.value)
}

// 装箱方式查询
const dialogVisible10 = ref(false)

const PackingMethodQueryTableDate = ref<any>([])

const PackingMethodQueryMethods = async () => {
  isLoading8.value = true
  const result = (await service.post('/mes/packBrand/getPcPackTypeList', {
    brand: packingMaterialsParms.value
  })) as any
  PackingMethodQueryTableDate.value = result.lotNoList
  isLoading8.value = false
}

// 整个品牌删除
const deleteWholeBrandMethods = async () => {
  const result = await deleteWholeBrand(deleteStyle.value)
  if (result.code === 200) {
    getTableDataList()
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

const deleteStyle = ref('')

const handleCloseMateriaLKlc7 = () => {
  if (deleteStyle.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteWholeBrandMethods()
      })
      .catch(() => {})
  }
}

// 物料资料建档
const formList5 = ref([
  {
    type: 'input',
    inputPlaceholder: '物料编号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '品名',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '单位',
    inputValue: ''
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '规格',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '颜色',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '毛重',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '净重',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '清空'
  },
  {
    type: 'button',
    checkboxLabel: '生成物料编码'
  },
  {
    type: 'button',
    checkboxLabel: '增加'
  }
])

// 材料明细新增
const MaterialDetailsAddedParms = ref<any>([
  {
    style: '',
    seqNo: '',
    typeName: '',
    mtlNo: '',
    mtlColor: '',
    mtlName: '',
    mtlSpec: '',
    mtlUnit: '',
    packType: '',
    size1: '',
    size2: '',
    usage: ''
  }
])

const MaterialDetailsAddedMethods = async () => {
  const result = await MaterialDetailsAdded(MaterialDetailsAddedParms.value)
  if (result.code === 200) {
    MaterialDetailnquiryMethods()
    dialogVisible7.value = false
    MaterialDetailsAddedParms.value = [
      {
        style: packingMaterialsParms.value,
        seqNo: deletepackingMaterialsParms.value.seqNo,
        typeName: deletepackingMaterialsParms.value.typeName,
        mtlNo: '',
        mtlColor: '',
        mtlName: '',
        mtlSpec: '',
        mtlUnit: '',
        packType: '',
        size1: '',
        size2: '',
        usage: ''
      }
    ]
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

// 选择材料修改
const checkboxChange1 = async (list: any) => {
  const result = await service.post<any, any>(`/mes/kf/sdMaterial/updateSdMaterial`, list)
  if (result.code === 200) {
    NewOrderDetailsMethods()

    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

const checkboxChange2 = async (list: any) => {
  list.style = MaterialDetailsAddedParms.value[0].style
  list.seqNo = MaterialDetailsAddedParms.value[0].seqNo
  list.typeName = MaterialDetailsAddedParms.value[0].typeName
  const result = await service.post<any, any>(`/BrandMaterialDefinition/updateMaterialDetail`, list)
  if (result.code === 200) {
    MaterialDetailnquiryMethods()
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

// 选择材料删除
const findData2 = (row: string) => {
  if (row === '删除') {
    handleCloseMateriaLKlc()
  }
  if (row === '确认') {
    if (MaterialDetailsAddedParms.value[0].packType === '') {
      JMessage.warning('装箱方式不可为空')
    } else if (MaterialDetailsAddedParms.value[0].mtlNo === '') {
      JMessage.warning('请选择需要新增的数据')
    } else {
      MaterialDetailsAddedMethods()
    }
  }
}
const currentTableRow7 = ref()
const currentRowList = (row: any) => {
  currentTableRow7.value = row
  mtlNoL.value = row.mtlNo

  MaterialDetailsAddedParms.value[0].mtlNo = row.mtlNo
  MaterialDetailsAddedParms.value[0].mtlColor = row.mtlColor
  MaterialDetailsAddedParms.value[0].mtlName = row.mtlName
  MaterialDetailsAddedParms.value[0].mtlSpec = row.mtlSpec
  MaterialDetailsAddedParms.value[0].mtlUnit = row.mtlUnit
}

const mtlNoL = ref('')

const deleteMtlNameMethods = async () => {
  const result = (await service.post(`/mes/kf/sdMaterial/deleteSdMaterial?id=${currentTableRow7.value.id}`)) as any
  if (result.code === 200) {
    NewOrderDetailsMethods()
    mtlNoL.value = ''
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

const handleCloseMateriaLKlc = () => {
  if (mtlNoL.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteMtlNameMethods()
      })
      .catch(() => {})
  }
}

// 增加
const AddGeneratedMaterialCodingParms = ref({
  grossWeight: '',
  mtlColor: '',
  mtlName: '',
  mtlNo: '',
  mtlSpec: '',
  mtlType: '',
  mtlTypeName: '',
  mtlUnit: '',
  netWeight: ''
})

const formList3 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '材料分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '材料名称',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '规格',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'input',
    inputPlaceholder: '指令',
    inputValue: '',
    inputLabel: ''
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '装箱方式',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '确认'
  }
])

const Launchform7 = (row: any) => {
  AddGeneratedMaterialCodingParms.value.mtlNo = row[0].inputValue
  AddGeneratedMaterialCodingParms.value.mtlName = row[1].inputValue
  AddGeneratedMaterialCodingParms.value.mtlUnit = row[2].inputValue
  AddGeneratedMaterialCodingParms.value.mtlType = row[3].selectValue.split(' ')[0]
  AddGeneratedMaterialCodingParms.value.mtlTypeName = row[3].selectValue.split(' ')[1]
  AddGeneratedMaterialCodingParms.value.mtlSpec = row[4].inputValue
  AddGeneratedMaterialCodingParms.value.mtlColor = row[5].inputValue
  AddGeneratedMaterialCodingParms.value.grossWeight = row[6].inputValue
  AddGeneratedMaterialCodingParms.value.netWeight = row[7].inputValue
}

const AddGeneratedMaterialCodingMethods = async () => {
  const result = (await service.post('/mes/kf/sdMaterial/addSdMaterial', AddGeneratedMaterialCodingParms.value)) as any
  if (result.code === 200) {
    clearFormList1()
    NewOrderDetailsMethods()
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

// 生成物料编码
// const GeneratedMaterialCodingParms  = ref({
//     grossWeight:"",
//     mtlColor:"",
//     mtlName:"",
//     mtlSpec:"",
//     mtlType:"",
//     mtlTypeName:"",
//     mtlUnit:"",
//     netWeight:"",
//     mtlNo:''
// })

const GeneratedMaterialCodingMethods = async () => {
  const result = (await service.post('/mes/kf/sdMaterial/makeSdMaterial', AddGeneratedMaterialCodingParms.value)) as any
  if (result.code === 200) {
    formList5.value[0].inputValue = result.data.mtlNo
    JMessage.success(result.msg)
  } else {
    NewOrderDetailsMethods()
    JMessage.error(result.msg)
  }
}

const currentRowList7 = (row: any) => {
  formList5.value[1].inputValue = row.mtlName
  formList5.value[2].inputValue = row.mtlUnit
  formList5.value[3].selectValue = row.mtlType
  formList5.value[4].inputValue = row.mtlSpec
  formList5.value[5].inputValue = row.mtlColor
  formList5.value[6].inputValue = row.grossWeight
  formList5.value[7].inputValue = row.netWeight
}

const clearFormList1 = () => {
  formList5.value.forEach((item) => {
    if (item.type === 'input') {
      item.inputValue = ''
    }
    if (item.type === 'select') {
      item.selectValue = ''
    }
  })
}

const findData5 = (count: string) => {
  if (count === '生成物料编码') {
    GeneratedMaterialCodingMethods()
  }
  if (count === '清空') {
    clearFormList1()
  }
  if (count === '增加') {
    if (AddGeneratedMaterialCodingParms.value.mtlName === '' || AddGeneratedMaterialCodingParms.value.mtlNo === '') {
      JMessage.warning('物料编号物料名称颜色不可为空')
    } else {
      AddGeneratedMaterialCodingMethods()
    }
  }
}

// 材料分类查询
const MaterialClassificationQueryMethods = async () => {
  const result = await MaterialClassificationQuery()
  const NewArrayList = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])

  formList3.value[0].selectOptions = EvaluatesTheArrayReturnValue1(NewArrayList)
  formList5.value[3].selectOptions = EvaluatesTheArrayReturnValue1(NewArrayList)
}

// 新增订购明细查询
const NewOrderDetailsParms = ref({
  grossWeight: '',
  mtlColor: '',
  mtlName: '',
  mtlNo: '',
  mtlSpec: '',
  mtlType: '',
  mtlTypeName: '',
  mtlUnit: '',
  netWeight: '',
  pageNum: 1,
  pageSize: 40
})

const Launchform3 = (row: any) => {
  NewOrderDetailsParms.value.mtlType = row[0].selectValue.split(' ')[0]
  NewOrderDetailsParms.value.mtlTypeName = row[0].selectValue.split(' ')[1]
  NewOrderDetailsParms.value.mtlName = row[1].inputValue
  NewOrderDetailsParms.value.mtlSpec = row[2].inputValue
  NewOrderDetailsMethods()

  MaterialDetailsAddedParms.value[0].packType = row[5].selectValue
}

const isLoading7 = ref(false)

const NewOrderDetailsTableDate = ref([])

const NewOrderDetailsMethods = async () => {
  isLoading7.value = true
  const result = (await service.post('/mes/kf/sdMaterial/getSdMaterial', NewOrderDetailsParms.value)) as any
  NewOrderDetailsTableDate.value = result.lotNoList.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  totalList1.value = result.total
  isLoading7.value = false
}

const totalList1 = ref(0)

const pageChange11 = (val: any) => {
  NewOrderDetailsParms.value.pageNum = val
  NewOrderDetailsMethods()
}

const pageSizeChange11 = (val: any) => {
  NewOrderDetailsParms.value.pageSize = val
  NewOrderDetailsMethods()
}

// 新增
// const

// const SelectMaterialNewMethods = async() => {
//   const result = await SelectMaterialNew()
// }

const dialogVisible7 = ref(false)

const isLoading = ref(true)
const isLoading2 = ref(false)
const isLoading3 = ref(true)
const isLoading4 = ref(true)

const DeleteSelectMaterialNewParms = ref('')

const DeleteSelectMaterialNewMethods = async () => {
  const result = await DeleteSelectMaterialNew(DeleteSelectMaterialNewParms.value)
  if (result.code === 200) {
    DeleteSelectMaterialNewParms.value = ''
    selectMaterialsMethods()
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

const handleCloseMateriaLKlc5 = () => {
  if (DeleteSelectMaterialNewParms.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        DeleteSelectMaterialNewMethods()
      })
      .catch(() => {})
  }
}

// 下拉框数据
const AddBrandDateMethods = async () => {
  let NewArray = []
  const result = await AddBrandDate()
  NewArray = result.lotNoList.reduce((arr: any, item: any) => {
    if (item.style) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.style)
    }
    return arr
  }, [])
  formList.value[7].selectOptions = EvaluatesTheArrayReturnValue3(NewArray)
  formList1.value[0].selectOptions = EvaluatesTheArrayReturnValue3(NewArray)
}

// 选择材料查询
const selectMaterialsTableDate = ref([])

const total = ref()

const selectMaterialsParms = ref({
  mtlName: '',
  mtlSpec: '',
  mtlType: '',
  pageNum: 1,
  pageSize: 40
})

const selectMaterialsMethods = async () => {
  const result = await selectMaterials(selectMaterialsParms.value)
  selectMaterialsTableDate.value = result.lotNoList
  total.value = result.total
}

const currentList = (row: any) => {
  AdddeletepackingParms.value = row
}

// 装箱数据
const PackingMethodMethods = async () => {
  let NewArray = []
  const result = await PackingMethod()
  NewArray = result.lotNoList.reduce((arr: any, item: any) => {
    if (item.packType) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.packType)
    }
    return arr
  }, [])
  formList2.value[4].selectOptions = EvaluatesTheArrayReturnValue3(NewArray)
  formList3.value[5].selectOptions = EvaluatesTheArrayReturnValue3(NewArray)
}

// 选择材料
const drawer3 = ref(false)

const EvaluatesTheArrayReturnValue3 = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const GainClassificationMehtods = async () => {
  let NewArray = []
  const result = await GainClassification()
  NewArray = result.reduce((arr: any, item: any) => {
    if (item.typeNo && item.typeName) {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.typeNo + ' ' + item.typeName)
    }
    return arr
  }, [])
  formList2.value[0].selectOptions = EvaluatesTheArrayReturnValue3(NewArray)
}

const formList2 = ref([
  {
    type: 'select',
    selectValue: '',
    selectP: '材料分类',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'input',
    inputPlaceholder: '材料名称',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '规格',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '装箱方式',
    selectLabel: '',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '确认'
  }
])

// 待出明细新增
const currentRowList1 = (row: any) => {
  const { mtlNo } = row
  DetailsToBeReleasedAddedMethodsParms.value = mtlNo
  DeleteSelectMaterialNewParms.value = mtlNo
}

const DetailsToBeReleasedAddedMethodsParms = ref('')

// 材料明细新增
const deleteMaterialDetailMethodsParms = ref()

const currentRowListOeder2 = (row: any) => {
  deleteMaterialDetailMethodsParms.value = row
  mtlNoList.value = row.mtlNo
}

const mtlNoList = ref('')

const deleteMaterialDetailMethods = async () => {
  const result = await deleteMaterialDetail(styleListParms.value, mtlNoList.value, deletepackingMaterialsParms.value)
  if (result.code === 200) {
    MaterialDetailnquiryMethods()
    deleteMaterialDetailMethodsParms.value = undefined
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

const handleCloseMateriaLKlc3 = () => {
  if (deleteMaterialDetailMethodsParms.value === undefined) {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteMaterialDetailMethods()
      })
      .catch(() => {})
  }
}

// 包材分类明细新增
const AdddeletepackingParms = ref<any>([])

const selectList = (row: any) => {
  AdddeletepackingParms.value = row.map((item: any) => {
    return item
  })
}

const AdddeletepackingMethods = async () => {
  if (Object.keys(AdddeletepackingParms.value).length === 0) {
    JMessage.warning('请选择需要新增的数据')
  } else {
    AdddeletepackingParms.value = AdddeletepackingParms.value.map((item: any) => {
      item.caluBase = item.caluBase.selectValue
      item.purFlag = item.purFlag === true ? 'Y' : null
      item.sizeFlag = item.sizeFlag === true ? 'Y' : null
      return item
    })
    const result = await Adddeletepacking(styleListParms.value, AdddeletepackingParms.value)
    if (result.code === 200) {
      packingMaterialsQueryMethods()
      dialogVisible1.value = false
      JMessage.success(result.msg)
    } else {
      JMessage.error(result.msg)
    }
  }
}

// 包材分类明细删除
const deletepackingMaterialsParms = ref({
  caluBase: '',
  purFlag: '',
  seqNo: -1,
  sizeFlag: '',
  typeName: ''
})

const handleCloseMateriaLKlc2 = () => {
  if (deletepackingMaterialsParms.value.seqNo === -1) {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deletepackingMaterialsMethods()
      })
      .catch(() => {})
  }
}

const deletepackingMaterialsMethods = async () => {
  const result = (await service.delete(`/mes/packBrand/deletePcPackType//${currentTable2DataRow.value.id}`)) as any
  if (result.code === 200) {
    packingMaterialsQueryMethods()
    deletepackingMaterialsParms.value.seqNo = -1
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

// 材料明细查询
const styleListParms = ref('')

const typeNameListParms = ref('')

const MaterialDetailnquiryMethodsTableDateList = ref<any>([])

const MaterialDetailnquiryMethods = async () => {
  isLoading2.value = true
  const result = await MaterialDetailnquiry(styleListParms.value, deletepackingMaterialsParms.value)
  MaterialDetailnquiryMethodsTableDateList.value = result.lotNoList.map((item: any) => {
    item.change = 'Y'
    item.disableConfirm = true
    return item
  })
  isLoading2.value = false
}

const currentTable2DataRow = ref<any>({})
const currentRowListOeder1 = (row: any) => {
  currentTable2DataRow.value = row
  const { caluBase, seqNo, typeName, sizeFlag } = row
  MaterialDetailsAddedParms.value[0].seqNo = seqNo
  typeNameListParms.value = typeName
  MaterialDetailsAddedParms.value[0].typeName = typeName

  deletepackingMaterialsParms.value.caluBase = caluBase.selectValue
  deletepackingMaterialsParms.value.seqNo = Number(seqNo)
  deletepackingMaterialsParms.value.typeName = typeName
  deletepackingMaterialsParms.value.sizeFlag = sizeFlag === true ? 'Y' : (null as any)

  MaterialDetailnquiryMethods()
}

// 选择分类
const dialogVisible1 = ref(false)

const packingMaterialsMethodsTableDateLsit = ref<any[]>([])

const packingMaterialsMethods = async () => {
  const result = await SelectackingMaterialClassification(styleListParms.value)
  packingMaterialsMethodsTableDateLsit.value = result.lotNoList.map((item: any) => {
    item.caluBase = {
      selectValue: item.caluBase === '1' ? '依指令数量计算' : '依外箱数量计算',
      options: []
    }

    if (item.sizeFlag === 'Y') {
      item.sizeFlag = true
    }

    if (item.purFlag === 'Y') {
      item.purFlag = true
    }
    if (item.existFlag === 'Y') {
      item.backgroundColor = '#3DEE11'
    }

    return item
  })
  isLoading3.value = false
}

const formList1 = ref([
  {
    type: 'select',
    selectValue: '',
    selectOptions: [],
    selectP: '品牌号'
  },
  {
    type: 'button',
    checkboxLabel: '确认添加'
  }
])

const selectedList = (_: any, row: any) => {
  change10(row, _)
}

const change10 = async (row: any, list: any) => {
  if (list.caluBase.selectValue === '') {
    list.caluBase = ''
  } else {
    list.caluBase = list.caluBase.selectValue === '依指令数量计算' ? '1' : '2'
  }
  list.sizeFlag = list.sizeFlag === true ? 'Y' : null

  delete list.disableConfirm
  delete list.change
  const result = await service.post<any, any>(`/BrandMaterialDefinition/updatePackagMaterial?style=${packingMaterialsParms.value}`, [list])
  if (result.code === 200) {
    packingMaterialsQueryMethods()
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

// 包材分类明细查询
const tableData2 = ref<any>([])

const packingMaterialsParms = ref('')

const packingMaterialsQueryMethods = async () => {
  const result = (await service.post('/mes/packBrand/getPcPackTypeList', {
    brand: packingMaterialsParms.value
  })) as any
  tableData2.value = result.lotNoList.map((item: any) => {
    if (item.caluBase === '') {
      item.caluBase = ''
      item.caluBase = {
        selectValue: '',
        options: [
          { value: '依指令数量计算', label: '依指令数量计算', item: '1' },
          { value: '依外箱数量计算', label: '依外箱数量计算', item: '2' },
          { value: '', label: '', item: '3' }
        ]
      }
    } else {
      item.caluBase = {
        selectValue: item.caluBase === '1' ? '依指令数量计算' : '依外箱数量计算',
        options: [
          { value: '依指令数量计算', label: '依指令数量计算', item: '1' },
          { value: '依外箱数量计算', label: '依外箱数量计算', item: '2' },
          { value: '', label: '', item: '3' }
        ]
      }
    }

    if (item.sizeFlag === 'Y') {
      item.sizeFlag = true
    }
    if (item.colorFlag !== null) {
      item.backgroundColor = '#00ff00'
    }
    item.disableConfirm = true
    item.change = 'Y'
    return item
  })
  if (tableData2.value.length > 0) {
    deletepackingMaterialsParms.value.caluBase = tableData2.value[0].caluBase.selectValue
    deletepackingMaterialsParms.value.seqNo = tableData2.value[0].seqNo
    deletepackingMaterialsParms.value.typeName = tableData2.value[0].typeName
    deletepackingMaterialsParms.value.sizeFlag = tableData2.value[0].sizeFlag === true ? 'Y' : (null as any)
    typeNameListParms.value = tableData2.value[0].typeName
    MaterialDetailsAddedParms.value[0].seqNo = tableData2.value[0].seqNo
    MaterialDetailsAddedParms.value[0].typeName = tableData2.value[0].typeName
    MaterialDetailnquiryMethods()
  }
  isLoading4.value = false
}

// 品牌删除
const deleteBrandParms = ref('')

const handleCloseMateriaLKlc1 = () => {
  if (deleteBrandParms.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteBrandMethods()
      })
      .catch(() => {})
  }
}
const currentTableDataRow = ref<any>({})
const currentRowListOeder = (row: any) => {
  currentTableDataRow.value = row
  const { style } = row
  deleteBrandParms.value = style
  packingMaterialsParms.value = style
  styleListParms.value = style
  MaterialDetailsAddedParms.value[0].style = style
  deleteStyle.value = style
  packingMaterialsQueryMethods()
}

const deleteBrandMethods = async () => {
  const result = (await service.delete(`/mes/packBrand/deletePcPackBrand/${currentTableDataRow.value.id}`)) as any
  if (result.code === 200) {
    getTableDataList()
    dialogVisible8.value = false
    JMessage.success(result.msg)
  } else {
    JMessage.error(result.msg)
  }
}

// 品牌添加
const findData1 = (cout: string) => {
  if (cout === '确认添加') {
    AddBrandMethods()
  }
}

const Launchform2 = (row: any) => {
  AddBrandList.value = row[0].selectValue
}

const AddBrandList = ref('')

const AddBrandMethods = async () => {
  if (AddBrandList.value === '') {
    JMessage.warning('请选择需要添加的数据')
  } else {
    const result = await service.post<any, any>(`/mes/packBrand/addPcPackBrand?brand=${AddBrandList.value}&deptType=${2}`)
    if (result.code === 200) {
      getTableDataList()
      dialogVisible8.value = false
      JMessage.success(result.msg)
    } else {
      JMessage.error(result.msg)
    }
  }
}

const EvaluatesTheArrayReturnValue1 = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item.style,
      optionLabel: item.style
    }
  })
}

const findData = (count: string) => {
  switch (count) {
    case '新增品牌': {
      dialogVisible8.value = true
      break
    }
    case '品牌删除': {
      handleCloseMateriaLKlc1()
      break
    }
    case '选择包材分类': {
      packingMaterialsMethods()
      dialogVisible1.value = true
      break
    }
    case '包材分类明细删除': {
      handleCloseMateriaLKlc2()
      break
    }
    case '材料明细删除': {
      handleCloseMateriaLKlc3()
      break
    }
    case '选择材料': {
      dialogVisible7.value = true
      NewOrderDetailsMethods()
      PackingMethodMethods()
      MaterialClassificationQueryMethods()
      break
    }
    case '整个品牌删除': {
      handleCloseMateriaLKlc7()
      break
    }
    case '定义装箱方式': {
      dialogVisible10.value = true
      PackingMethodQueryMethods()
    }
  }
}

// 品牌搜索
const Launchform1 = (row: any) => {
  styleList.value = row[0].inputValue
  getTableDataList()
}

// 品牌新增
const dialogVisible8 = ref(false)

// 品牌查询
const styleList = ref('')

const tableData = ref([])

const getTableDataList = async () => {
  const result = (await service.post('/mes/packBrand/getPcPackBrandList', {
    brand: styleList.value
  })) as any
  tableData.value = result.data
  if (result.data.length > 0) {
    packingMaterialsParms.value = result.data[0].style
    styleListParms.value = result.data[0].style
    MaterialDetailsAddedParms.value[0].style = result.data[0].style
    packingMaterialsQueryMethods()
  }
  isLoading.value = false
}

onMounted(() => {
  getTableDataList()

  AddBrandDateMethods()
})

const formList = ref([
  {
    type: 'input',
    inputPlaceholder: '请输入品牌',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '新增品牌'
  },
  {
    type: 'button',
    checkboxLabel: '品牌删除'
  },

  {
    type: 'button',
    checkboxLabel: '选择包材分类'
  },
  {
    type: 'button',
    checkboxLabel: '包材分类明细删除'
  },
  {
    type: 'button',
    checkboxLabel: '选择材料'
  },
  {
    type: 'button',
    checkboxLabel: '材料明细删除'
  },

  {
    type: 'select',
    selectValue: '',
    selectLabel: '',
    selectOptions: [],
    selectP: '品牌号'
  },

  {
    type: 'button',
    checkboxLabel: '复制包材分类'
  },

  {
    type: 'button',
    checkboxLabel: '定义装箱方式'
  },

  {
    type: 'button',
    checkboxLabel: '整个品牌删除'
  }
])

const tableHeader = ref([
  {
    label: '品牌',
    prop: 'style'
  }
])

const tableHeader2 = ref([
  {
    label: '包材分类',
    prop: 'typeName',
    backgroundColor: true,
    change: true
  },
  {
    type: 'select',
    label: '计算来源',
    prop: 'caluBase',
    cahnge: true
  },
  {
    type: 'checkbox',
    label: '按号码分段计算',
    prop: 'sizeFlag',
    cahnge: true
  }
])

const tableHeader3 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo',
    change: true
  },
  {
    label: '材料类型',
    prop: 'mtlType',
    change: true
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '颜色',
    prop: 'mtlColor',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '毛重',
    prop: 'grossWeight'
  },
  {
    label: '净重',
    prop: 'netWeight'
  }
])

const tableHeader7 = ref([
  {
    label: '物料编码',
    prop: 'mtlNo',
    change: true
  },
  {
    label: '颜色',
    prop: 'mtlType',
    change: true
  },
  {
    label: '材料名称',
    prop: 'mtlName',
    change: true
  },
  {
    label: '规格',
    prop: 'mtlSpec',
    change: true
  },
  {
    label: '单位',
    prop: 'mtlColor',
    change: true
  },
  {
    label: '装箱方式',
    prop: 'mtlUnit',
    change: true
  },
  {
    label: '号码起',
    prop: 'grossWeight'
  },
  {
    label: '号码止',
    prop: 'netWeight'
  },
  {
    label: '用量比()',
    prop: 'usage'
  }
])

const tableHeader10 = ref([
  {
    label: '序号方式',
    prop: 'seqNo'
  },
  {
    label: '装箱方式',
    prop: 'packType'
  },
  {
    label: '每箱双数',
    prop: 'caseQty'
  }
])

const tableHeader5 = ref([
  {
    label: '序号',
    prop: 'seqNo',
    change: 'true',
    width: '55'
  },
  {
    label: '包材类别',
    prop: 'typeName',
    width: '120',
    backgroundColor: true
  },
  {
    type: 'select',
    label: '计算来源',
    prop: 'caluBase',
    width: '120'
  },
  {
    type: 'checkbox',
    label: '按号码分段计算',
    prop: 'sizeFlag',
    width: '120'
  },
  {
    type: 'checkbox',
    label: '采购部类别选择',
    prop: 'purFlag',
    width: '120'
  }
])
</script>

<style lang="less" scoped>
.main {
  width: 100%;
  background-color: white;
}

.btns {
  display: flex;
  padding: 10px 35px 5px;
  justify-content: end;

  .bg {
    background-color: #e7e7e7;
    border: 1px solid #e7e7e7;
    color: #000000;
  }
}

.table1 {
  :deep(th:nth-child(10)) {
    color: red !important;
  }
}
</style>
